<?php
/**
 *author:栗超
 *address:2788547340@qq.com
 * 2016/8/26 17:29
*/
namespace Home\Controller;
use Common\Model\Goods;
use Common\Model\GoodsAttr;
use Common\Model\GoodsDetail;
use Common\Model\TypeAttr;
use Hdphp\Controller\Controller;
class GoodsController extends Controller{
    public  function  index(){
        $goodsModel=new Goods();
        $gid=Q('get.gid',0,'intval');
        $data=$goodsModel
            ->join('goods_detail','gid','=','goods_gid')
            ->where("goods_gid={$gid}")
            ->get();
//        p($data);
        View::with('data',$data);
        //商品的属性
        $goodsAttrModel=new GoodsAttr();
        $goodsAttrData=$goodsAttrModel
                      ->join('type_attr','type_attr_taid','=','taid')
                      ->where("goods_gid={$gid} AND class=1")
                      ->groupBy('taid')
                      ->get();
        foreach ($goodsAttrData as $k=>$v){
            $goodsAttrData[$k]['value']=$goodsAttrModel
                ->where("type_attr_taid={$v['taid']} AND goods_gid={$gid}")
                ->lists('gaid,gavalue');

        }
//                    p($goodsAttrData);
        View::with('goodsAttrData',$goodsAttrData);
        $goodsDetailModel=new GoodsDetail();
        $detailData=$goodsDetailModel
                    ->where("goods_gid={$gid}")
                    ->get();
//            p($detailData);
        $detailData=explode(',',$detailData[0]['picintro'] );
//        p($detailData);
        View::with('detailData',$detailData);
        View::make();
    }


}


?>
